fix(mcp): use POST /v4/memories + add test suite reproducing v3 bug#1040
fix(mcp): use POST /v4/memories + add test suite reproducing v3 bug#1040ZongrongLi wants to merge 3 commits into
Conversation
…eation The SDK's client.add() calls POST /v3/documents which uses the document upload pipeline. This pipeline fails to process plain-text memory content — all documents created this way end up with status: 'failed' and 0 memory entries. POST /v4/memories is the correct endpoint for plain-text memory creation. Memories created via v4 are immediately searchable. Before: 19/19 documents failed (0 memories) After: 22/22 memories active and searchable
The MCP client's createMemory() previously threw a raw Error for non-ok HTTP
responses. handleError() checks for a .status property to dispatch per-status
messages — without it every status came back as 'Failed to create memory: N'.
Fix: attach .status to the error object before throwing.
Test coverage (12 tests, all pass):
- Endpoint: POST /v4/memories vs POST /v3/documents (the bug)
- Payload format: {containerTag, memories: [{content, metadata}]}
- Response mapping: status, id, containerTag
- Auth header passthrough
- Error handling: 401 / 402 / 429 / 500 / network error
- Contract guard: v3 vs v4 payload shapes
|
All alerts resolved. Learn more about Socket for GitHub. This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored. |
…critical RCE (GHSA-9qr9-h5gf-34mp) Socket flagged next@16.0.3 as a Critical CVE (RCE in React flight protocol). Aligning with apps/web (^16.0.11); both now dedupe to next@16.1.6. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
c08668e to
b1de8a0
Compare
ishaanxgupta
left a comment
There was a problem hiding this comment.
Can we either remove the unrelated apps/memory-graph-playground/package.json & bun.lock churn?
ishaanxgupta
left a comment
There was a problem hiding this comment.
Please regenerate bun.lock from the repo’s normal registry/settings and remove the unrelated dependency changes. The current lockfile rewrites a large number of package entries from an empty registry URL to https://registry.npmmirror.com/..., which would churn dependency provenance across the whole workspace. It also changes apps/memory-graph-playground from next@16.0.3 to ^16.0.11, which is unrelated to the MCP /v4/memories fix. The PR should ideally only include the MCP client/test changes plus the minimal lockfile entries needed for the added test dependency.
Related Issue
Related to #792 (Claude Code plugin writes memories but recall/search returns empty — same write-path root cause for MCP users; issue #792 may also involve a separate read-path bug in the plugin)
Problem
The MCP
createMemory()method calls the SDK’sclient.memories.add(), which maps toPOST /v3/documents. This endpoint routes through the document ingestion workflow (IngestContentWorkflow) that handles extraction, summarization, chunking, and embedding — designed for URLs, PDFs, images, and file uploads.When plain text is sent through this pipeline:
"failed"Real-world impact: 19/19 documents created by the MCP end up with status=failed. Users report "memories saved but search returns empty" (#792).
Original Design Decision
The original author used
client.memories.add()because it was the only.add()method exposed by the SDK. However, the entireclient.memoriesSDK class is misnamed — it operates on/v3/documents/*endpoints (list, update, delete, get documents). It is a document resource, not a memory resource.The correct API for storing plain-text memories is
POST /v4/memories, explicitly documented inapps/docs/memory-operations.mdx:(Source: apps/docs/memory-operations.mdx, lines 15-20)
Fix (2 commits)
Commit 1: Replace
client.add()with direct fetch toPOST /v4/memoriesBefore:
After:
Commit 2: Fix HTTP error dispatch
The
!response.okbranch threw a rawErrorwithout a.statusproperty. The existinghandleError()method dispatches status codes (401=reauth, 402=upgrade, 429=backoff, 500=retry) via"status" in error— without it every failure returned the same generic message.Fix: Attach
error.status = response.statusbefore throwing.Test Coverage (12 tests, all pass)
The test suite uses vitest to mock
fetch()and verify every code path:Run with:
Verification
After the fix, 22/22 memories created via MCP are active and searchable (previously 19/19 failed). Verified on supermemory.ai web UI and through API search.
Files Changed
apps/mcp/src/client.tsapps/mcp/src/__tests__/supermemory-client.test.tsapps/mcp/vitest.config.tsapps/mcp/package.jsonbun.lock